package com.firebird.app.kotlin.stock.trend.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.widget.Toast

/**
 * 网络状态监听器
 * @author ljk
 * @date   2019年12月23日
 */
class NetStatusReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
        val wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
        val activeInfo = manager.activeNetworkInfo
        Toast.makeText(context, "mobile:" + mobileInfo.isConnected + " wifi:" + wifiInfo.isConnected + " active:" + activeInfo.typeName, Toast.LENGTH_SHORT).show()
    }
}
